package totask.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import totask.pojo.TotaskProject;
import totask.pojo.TotaskTask;
import totask.response.ResponseData;

import totask.service.impl.TaskServiceImpl;
import totask.vo.TotaskTaskVo;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@Api(tags = "任务信息")
@RestController
@Validated
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskServiceImpl taskService;
    
    @ApiOperation("根据项目id查询所有任务详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ProjectId", value = "项目id", dataType = "Integer", required = true),
    })
    @GetMapping("/TaskAll")
    public ResponseData<List<TotaskTask>> queryTaskAll(@RequestParam  @Min(value = 1, message = "项目id不能小于1") Integer ProjectId){
        return new ResponseData<List<TotaskTask>>().success(taskService.queryTaskAll(ProjectId));
    }

    @ApiOperation("新建任务信息")
    @PostMapping("/insertTaskInfo")
    public ResponseData insertTask(@Valid @RequestBody TotaskTask totaskTask){
        ResponseData responseData = new ResponseData();
        responseData.setData(taskService.insertTask(totaskTask));
        return responseData.success();
    }
    @ApiOperation("根据任务id修改任务")
    @PostMapping("/updateTaskInfo")
    public ResponseData updateTask(@Valid @RequestBody TotaskTask task){
        ResponseData responseData = new ResponseData();
        responseData.setData(taskService.updateTask(task));
        return responseData.success();
    }

    @ApiOperation("根据用户id查询用户任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userid", value = "用户id", dataType = "String", required = true),
    })
    @PostMapping("/queryUserTaskInfo")
    public ResponseData<TotaskTaskVo> queryUserTaskAll(@RequestParam  @NotBlank(message = "用户id不能为空")String userid){
        return new ResponseData<TotaskTaskVo>().success(taskService.queryUserTaskAll(userid));
    }
//    @ApiOperation("根据项目id查询任务详情信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ProjectId", value = "项目id", dataType = "Integer", required = true),
//    })
//    @PostMapping("/queryByTaskInfo")
//    public ResponseData queryByTask(@RequestParam  @Min(value = 1, message = "项目id不能小于1") Integer ProjectId){
//        return new ResponseData().success(taskService.queryByTask(ProjectId));
//    }
    @ApiOperation("根据项目id统计，项目进度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ProjectId", value = "项目id", dataType = "Integer", required = true),
    })
    @PostMapping("/queryProjectProgress")
    public ResponseData<Map<String,Integer>> queryProjectProgress(@RequestParam  @Min(value = 1, message = "项目id不能小于1") Integer ProjectId){
        return new ResponseData<Map<String,Integer>>().success(taskService.queryProjectProgress(ProjectId));
    }

    @ApiOperation("根据用户id，项目id，查询任务进度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ProjectId", value = "项目id", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "userid", value = "用户id", dataType = "String", required = true),
            @ApiImplicitParam(name = "roleId", value = "角色id", dataType = "Integer", required = true),
    })
    @PostMapping("/queryTaskProgress")
    public ResponseData<Map<String,Integer>> queryProjectUserProgress(@RequestParam  @Min(value = 1, message = "项目id不能小于1") Integer ProjectId,
              @RequestParam  @NotBlank(message = "用户id不能为空")String userid,@RequestParam  @Min(value = 1, message = "角色id不能小于1") Integer roleId){
        return new ResponseData<Map<String,Integer>>().success(taskService.queryTaskProgress(ProjectId,userid,roleId));
    }

}
